#include "player.h"

Player::Player(int id, QColor col, QObject *parent) :
    QObject(parent)
{
    this->id = id;
    this->col = col;

    prn = qobject_cast<QWidget*>(parent);

    plb = new PlBord(prn);

    bobs.reserve(pcs);
    for (int i = 0; i < pcs; ++i) {
        bobs << new Bob( i, id, col, plb);
    }

    for (int i = 0; i < pcs; ++i) {
//        plb->lay->addWidget(bobs[i]);
        plb->addbob(bobs[i]);
    }

    used_bobs = 0;
    lost_bobs = 0;
    pts = 0;

}


bool Player::islandlocked() {
    bool r = true;

    for (int i=0; i< Player::pcs; ++i) {
        if (bobs[i]->state == Bob::unused) {
            r = false;
            break;
        } else if (bobs[i]->state == Bob::ingame) {
            for (int j=0; j < bobs[i]->nest->neighs.size(); ++j) {
                if (bobs[i]->nest->neighs[j]->empty) {
                    r = false;
                    break;
                }
            }
            if (!r) break;
        }
    }

    return r;
}
